package net.lab1024.sa.admin.module.aneswork.anes;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import net.lab1024.sa.admin.module.aneswork.anes.domain.AnesWorkEntity;

import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.domain.QueryForm;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.util.SmartLocalDateUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.util.SmartRequestUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;




@Service
@Slf4j
public class AnesworkService {
    @Resource
    private AnesworkDao anesworkDao;

    /**
     * 分页查询麻醉工作量
     */
    public ResponseDTO<PageResult<AnesWorkEntity>> queryByPage(QueryForm queryForm) {

        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        queryForm.setCreatePeople(SmartRequestUtil.getRequestUser().getUserNum());
        List<AnesWorkEntity> invoiceList = anesworkDao.queryPage(page, queryForm);
        PageResult<AnesWorkEntity> pageResult = SmartPageUtil.convert2PageResult(page, invoiceList);
        return ResponseDTO.ok(pageResult);
    }



    /**
     * 麻醉所有工作量
     */
    public ResponseDTO<List<AnesWorkEntity>> queryAll()  {
        List<AnesWorkEntity> anesWorkList = anesworkDao.selectList(null);
        // 将查询结果封装到ResponseDTO中并返回
        return ResponseDTO.ok(anesWorkList);
    }


    /**
     * 根据ID查询工作量
     */
    public ResponseDTO<AnesWorkEntity> queryById(Integer id)  {
        AnesWorkEntity anesWorkList = anesworkDao.selectById(id);
        // 将查询结果封装到ResponseDTO中并返回
        return ResponseDTO.ok(anesWorkList);
    }


    public ResponseDTO<String> update(AnesWorkEntity data) {
        anesworkDao.updateById(data);
        return ResponseDTO.ok();
    }

    public ResponseDTO<String> delete(AnesWorkEntity data) {
        anesworkDao.deleteById(data.getId());
        return ResponseDTO.ok();
    }



    /**
     * 新增麻醉工作量
     */
    public ResponseDTO<String> add(AnesWorkEntity data) {
       data.setCreatePeople(SmartRequestUtil.getRequestUser().getUserNum());
       data.setCreateTime(SmartLocalDateUtil.toLocalDateTime(new Date()));
       data.setId(null);
        anesworkDao.insert(data);
        return ResponseDTO.ok();
    }



}
